package com.pointi.emoGatewayM ;

import org.w3c.dom.Document ;
import org.w3c.dom.Element ;
import org.w3c.dom.Node ;
import org.w3c.dom.NodeList ;

import com.pointi.emoTools.emoLicense ;

public class ConfigurationData extends emoLicense
{
	// GATEWAY
	public String s_gateway_address = "" ;
	public String s_gateway_port = "" ;
	public String s_gateway_org_path = "" ;
	public String s_gateway_tgt_path = "" ;
	public String s_converter_limit = "" ;
	public String s_thread_limit = "" ;
	public String s_check_interval = "" ;

	public ConfigurationData() {}

	public void InitializeData()
	{
		// GATEWAY
		s_gateway_address = "" ;
		s_gateway_port = "" ;
		s_gateway_org_path = "" ;
		s_gateway_tgt_path = "" ;
		s_thread_limit = "" ;
		super.InitializeData() ;
	}

	public ConfigurationData ReadConfXML(String strFile) throws Exception
	{
		NodeList mCATEGORY = null ;
		Node mNode = null ;
		ConfigurationData conf_data = new ConfigurationData() ;
		try
		{
			Document doc = super.ReadConfXML(strFile, conf_data) ;
			doc.getDocumentElement().normalize() ;
			if (doc.getDocumentElement().getNodeName().equals("configuration"))
			{
				// CONF | CATEGORY | GATEWAY
				mCATEGORY = doc.getElementsByTagName("gateway") ;
				mNode = mCATEGORY.item(0) ;
				if (mNode.getNodeType() == Node.ELEMENT_NODE)
				{
					Element mElmnt = (Element) mNode ; // TYPE_CAST
					conf_data.s_gateway_address = fnReadTerminal(mElmnt, "address") ;
					conf_data.s_gateway_port = fnReadTerminal(mElmnt, "port") ;
					conf_data.s_gateway_org_path = fnReadTerminal(mElmnt, "org_path") ;
					conf_data.s_gateway_tgt_path = fnReadTerminal(mElmnt, "tgt_path") ;
					conf_data.s_thread_limit = fnReadTerminal(mElmnt, "thread_limit") ;
					conf_data.s_check_interval = fnReadTerminal(mElmnt, "check_interval") ;
					conf_data.s_converter_limit = fnReadTerminal(mElmnt, "converter_limit") ;
				}
			}
		} catch (Exception e) { e.printStackTrace() ; }		
		return conf_data ;
	}

	public void WriteLogConfigurationData(ConfigurationData conf_data)
	{
		super.WriteLogConfigurationData(conf_data) ;
		System.out.println("------------------ gateway ------------------") ;
		System.out.println("serverip	: " + conf_data.s_gateway_address) ;
		System.out.println("serverport	: " + conf_data.s_gateway_port) ;
		System.out.println("orgpath		: " + conf_data.s_gateway_org_path) ;
		System.out.println("tgtpath		: " + conf_data.s_gateway_tgt_path) ;
		System.out.println("threadlimit	: " + conf_data.s_thread_limit) ;
		System.out.println("chkinterval	: " + conf_data.s_check_interval) ;
		System.out.println("cvtlimit	: " + conf_data.s_converter_limit) ;
		System.out.println("---------------------------------------------") ;
	}
}
